<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客编辑页</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/edit.css">
    <link rel="stylesheet" href="blog-editormd/css/editormd.css" />

</head>

<body>
    <div class="nav">
        <img src="https://tse3-mm.cn.bing.net/th/id/OIP-C.wb9I_pEZGVG3RIQtuLCXNQHaHZ?w=181&h=180&c=7&r=0&o=7&dpr=1.3&pid=1.7&rm=3" alt="">
        <span class="blog-title">我的博客系统</span>
        <div class="space"></div>
        <a class="nav-span" href="blog_list.html">主页</a>
        <a class="nav-span" href="blog_edit.html">写博客</a>
        <a class="nav-span" href="#" onclick="logout()">注销</a>
    </div>
    <div class="content-edit">
        <div class="push">
            <input type="text" name="" id="title">
            <input type="button" value="发布文章" id="submit" onclick="submit()">
        </div>
        <!-- markdown 插件 html代码 -->
        <div id="editor">
            <textarea style="display:none;" id="content" name="content">##在这里写下一篇博客</textarea>
        </div>
    </div>

    <script src="js/jquery.min.js"></script>
    <script src="blog-editormd/editormd.min.js"></script>
    <script src="js/common.js"></script>
    <script type="text/javascript">

        $(function () {
            var editor = editormd("editor", {
                width: "100%",
                height: "550px",
                path: "blog-editormd/lib/"
            });

        });

        function submit() {
            var title = $("#title").val();
            var content = $("#content").val();
            $.ajax({
                type: "POST",
                url: "blog/insertBlog",
                contentType: "application/json",
                data: JSON.stringify({
                    "title": title,
                    "content": content
                }),
                success: function (result) {
                    console.log(result);
                    if (result.code == "Success") {
                        alert("发布成功");
                        location.assign("blog_list.html");
                    } else {
                        console.log(result);
                        alert(result.errMessage);
                    }
                },
                error: function (result) {
                    console.log(result);
                    if (result.status == 401){
                        alert("请先登录")
                        location.assign("blog_login.html");
                    }
                }
            })
        }

    </script>
</body>

</html>